from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QSystemTrayIcon
import os, sys

class Tray(QtGui.QSystemTrayIcon):

    activated = None
    cfg = None
    def __init__(self, cfg):
        self.cfg = cfg
        QtGui.QSystemTrayIcon.__init__(self, cfg)
        self.icon=QSystemTrayIcon()
        self.icon.setIcon( QtGui.QIcon(os.getcwd()+'/tray.png') )
        self.iconMenu = QtGui.QMenu()
        self.ignoreList = self.iconMenu.addAction("Ignore list")
        self.about = self.iconMenu.addAction("About")
        self.quit = self.iconMenu.addAction("Quit")
        self.icon.setContextMenu(self.iconMenu)
        self.icon.show()
        self.icon.activated.connect(self.activate)
        
        self.connect(self.quit,QtCore.SIGNAL('triggered()'),self.exit)

    def exit(self):
        sys.exit()
        
    def activate(self,reason):
        if reason == 3:
            if self.cfg.isActiveWindow():
                self.cfg.hide()
            else:
                self.cfg.show()
                self.cfg.activateWindow()